<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
         let msg = "默认消息";
         window.onload=function(){
            document.querySelector("#msg").innerHTML=msg;
            userInput=document.querySelector("#userInput");
            userInput.value=msg;
            userInput.addEventListener('input',function(){
                // msg=this.value;
                msg=userInput.value;
                document.querySelector("#msg").innerHTML=msg;
            })
            let showBtn=document.querySelector("#showBtn");
            showBtn.onclick=function(){
                alert(msg);
            }
         }
    </script>
</head>
<body>
    <div>
        <h1 id="msg"></h1>
        <input type="text" id="userInput" >
        <br><br>
        <input type="button" value="消息" id="showBtn">
    </div>
</body>
</html>